package Z.dailyExercise.May;

public class _279完全平方数 {


    /**
     * 题解：有点像凑钱
     * 动态规划
     * @param n
     * @return
     */
    public int numSquares(int n) {
        int[] dp = new int[n+1];
        
        for (int i = 1; i < n+1; i++) {
            dp[i] = i;
            for (int j = 1; i-j*j > 0 ; j++) {
                dp[i] = Math.min(dp[i],dp[i-j*j]+1);
            }
        }
        return dp[n];


    }
}
